﻿using System;
using System.Collections.Generic;

namespace SharpSqlAnalyzer.nodes
{
	// Token: 0x02000341 RID: 833
	public class TResultColumn : TNodeWithAliasClause
	{
		// Token: 0x170006F5 RID: 1781
		// (get) Token: 0x06002215 RID: 8725 RVA: 0x00334991 File Offset: 0x00332B91
		// (set) Token: 0x06002216 RID: 8726 RVA: 0x00334999 File Offset: 0x00332B99
		public TQualifyClause qualifyClause
		{
			get
			{
				return this._qualifyClause;
			}
			set
			{
				this._qualifyClause = value;
			}
		}

		// Token: 0x170006F6 RID: 1782
		// (set) Token: 0x06002217 RID: 8727 RVA: 0x003349A2 File Offset: 0x00332BA2
		public virtual List<TExplicitDataTypeConversion> DataTypeConversionList
		{
			set
			{
				this.expr.DataTypeConversionList = value;
			}
		}

		// Token: 0x170006F7 RID: 1783
		// (get) Token: 0x06002218 RID: 8728 RVA: 0x003349B0 File Offset: 0x00332BB0
		// (set) Token: 0x06002219 RID: 8729 RVA: 0x003349CB File Offset: 0x00332BCB
		public virtual TObjectNameList TargetColumns
		{
			get
			{
				if (this.targetColumns == null)
				{
					this.targetColumns = new TObjectNameList();
				}
				return this.targetColumns;
			}
			set
			{
				this.targetColumns = value;
			}
		}

		// Token: 0x0600221A RID: 8730 RVA: 0x003349D4 File Offset: 0x00332BD4
		public virtual bool isMatchedWithResultColumn(TObjectName pColumn)
		{
			bool flag = pColumn.ColumnNameOnly.Equals(this.ColumnAlias, StringComparison.CurrentCultureIgnoreCase);
			if (!flag)
			{
				flag = pColumn.ColumnNameOnly.Equals(this.ColumnNameOnly, StringComparison.CurrentCultureIgnoreCase);
			}
			return flag;
		}

		// Token: 0x0600221B RID: 8731 RVA: 0x00334A0B File Offset: 0x00332C0B
		public virtual void TResultColumn_Renamed()
		{
		}

		// Token: 0x170006F8 RID: 1784
		// (get) Token: 0x0600221C RID: 8732 RVA: 0x00334A0D File Offset: 0x00332C0D
		public virtual string ColumnAlias
		{
			get
			{
				if (this.AliasClause != null)
				{
					return this.AliasClause.ToString();
				}
				return "";
			}
		}

		// Token: 0x170006F9 RID: 1785
		// (get) Token: 0x0600221D RID: 8733 RVA: 0x00334A28 File Offset: 0x00332C28
		public virtual string ColumnNameOnly
		{
			get
			{
				if (this.expr.ExpressionType == EExpressionType.simple_object_name_t)
				{
					return this.expr.ObjectOperand.ColumnNameOnly;
				}
				return "";
			}
		}

		// Token: 0x170006FA RID: 1786
		// (get) Token: 0x0600221F RID: 8735 RVA: 0x00334A57 File Offset: 0x00332C57
		// (set) Token: 0x0600221E RID: 8734 RVA: 0x00334A4E File Offset: 0x00332C4E
		public virtual TExpression Expr
		{
			get
			{
				return this.expr;
			}
			set
			{
				this.expr = value;
			}
		}

		// Token: 0x170006FB RID: 1787
		// (get) Token: 0x06002221 RID: 8737 RVA: 0x00334A68 File Offset: 0x00332C68
		// (set) Token: 0x06002220 RID: 8736 RVA: 0x00334A5F File Offset: 0x00332C5F
		public virtual bool PlaceHolder
		{
			get
			{
				return this.placeHolder;
			}
			set
			{
				this.placeHolder = value;
			}
		}

		// Token: 0x06002222 RID: 8738 RVA: 0x00334A70 File Offset: 0x00332C70
		public override void init(object arg1)
		{
			if (arg1 is TExpression)
			{
				this.expr = (TExpression)arg1;
			}
		}

		// Token: 0x06002223 RID: 8739 RVA: 0x00334A86 File Offset: 0x00332C86
		public override void init(object arg1, object arg2)
		{
			this.init(arg1);
			if (arg2 is TAliasClause)
			{
				this.AliasClause = (TAliasClause)arg2;
				if (((TAliasClause)arg2).AliasName != null)
				{
					((TAliasClause)arg2).AliasName.ObjectType = 2;
				}
			}
		}

		// Token: 0x06002224 RID: 8740 RVA: 0x00334AC4 File Offset: 0x00332CC4
		public override void doParse(TCustomSqlStatement psql, ESqlClause plocation)
		{
			if (this.PlaceHolder)
			{
				return;
			}
			if (psql.dbvendor == EDbVendor.dbvteradata && this.expr.DataTypeConversionList != null)
			{
				TDatatypeAttribute tdatatypeAttribute = null;
				for (int i = 0; i < this.expr.DataTypeConversionList.Count; i++)
				{
					TExplicitDataTypeConversion texplicitDataTypeConversion = this.expr.DataTypeConversionList[i];
					if (texplicitDataTypeConversion.DataTypeAttributeList1 != null)
					{
						for (int j = 0; j < texplicitDataTypeConversion.DataTypeAttributeList1.Count; j++)
						{
							tdatatypeAttribute = texplicitDataTypeConversion.DataTypeAttributeList1[j];
							if (tdatatypeAttribute.AttributeType == EDataTypeAttribute.named_t)
							{
								break;
							}
							tdatatypeAttribute = null;
						}
						if (tdatatypeAttribute != null)
						{
							break;
						}
					}
				}
				if (tdatatypeAttribute != null && tdatatypeAttribute.AttributeType == EDataTypeAttribute.named_t)
				{
					TAliasClause taliasClause = new TAliasClause();
					if (tdatatypeAttribute.Value_literal != null)
					{
						taliasClause.init(tdatatypeAttribute.Value_literal);
						taliasClause.startToken = tdatatypeAttribute.Value_literal.startToken;
						taliasClause.endToken = tdatatypeAttribute.Value_literal.endToken;
					}
					else if (tdatatypeAttribute.Value_identifier != null)
					{
						taliasClause.init(tdatatypeAttribute.Value_identifier);
						taliasClause.startToken = tdatatypeAttribute.Value_identifier.startToken;
						taliasClause.endToken = tdatatypeAttribute.Value_identifier.endToken;
					}
					taliasClause.TeradataNamedAlais = true;
					taliasClause.AsToken = tdatatypeAttribute.startToken;
					this.AliasClause = taliasClause;
				}
			}
			if (plocation == ESqlClause.set)
			{
				if (this.expr.ExpressionType == EExpressionType.function_t)
				{
					this.expr.FunctionCall.FunctionName.ObjectType = 11;
					psql.linkColumnReferenceToTable(TGSharpSqlParser.parseObjectName(psql.dbvendor, this.expr.FunctionCall.FunctionName.PartToken.astext), plocation);
					return;
				}
				if (this.expr.LeftOperand.ExpressionType == EExpressionType.simple_object_name_t)
				{
					this.expr.LeftOperand.ObjectOperand.Location = plocation;
					psql.tables.getTable(0).LinkedColumns.addObjectName(this.expr.LeftOperand.ObjectOperand);
					this.expr.LeftOperand.ObjectOperand.SourceTable = psql.tables.getTable(0);
					psql.tables.getTable(0).ObjectNameReferences.addObjectName(this.expr.LeftOperand.ObjectOperand);
					this.expr.RightOperand.doParse(psql, ESqlClause.setValue);
					return;
				}
				this.expr.doParse(psql, plocation);
				return;
			}
			else
			{
				if (this.expr.ExpressionType == EExpressionType.simple_comparison_t && (psql.dbvendor == EDbVendor.dbvmssql || psql.dbvendor == EDbVendor.dbvsybase) && (plocation == ESqlClause.resultColumn || plocation == ESqlClause.insertColumn || plocation == ESqlClause.mergeInsert || plocation == ESqlClause.selectList))
				{
					if (this.expr.ComparisonOperator.ToString().Equals("=", StringComparison.CurrentCultureIgnoreCase) && !this.expr.LeftOperand.ToString().StartsWith("@", StringComparison.Ordinal))
					{
						this.expr.ExpressionType = EExpressionType.sqlserver_proprietary_column_alias_t;
					}
					this.expr.doParse(psql, plocation);
					return;
				}
				this.expr.doParse(psql, plocation);
				return;
			}
		}

		// Token: 0x170006FC RID: 1788
		// (get) Token: 0x06002225 RID: 8741 RVA: 0x00334DC4 File Offset: 0x00332FC4
		public virtual TObjectName FieldAttr
		{
			get
			{
				TObjectName result = null;
				if (this.expr.ExpressionType == EExpressionType.simple_object_name_t)
				{
					result = this.expr.ObjectOperand;
				}
				return result;
			}
		}

		// Token: 0x170006FD RID: 1789
		// (get) Token: 0x06002226 RID: 8742 RVA: 0x00334DEE File Offset: 0x00332FEE
		public virtual string PrefixTable
		{
			get
			{
				if (this.FieldAttr == null)
				{
					return "";
				}
				return this.FieldAttr.TableString;
			}
		}

		// Token: 0x170006FE RID: 1790
		// (get) Token: 0x06002227 RID: 8743 RVA: 0x00334E09 File Offset: 0x00333009
		public virtual string PrefixSchema
		{
			get
			{
				if (this.FieldAttr == null)
				{
					return "";
				}
				return this.FieldAttr.SchemaString;
			}
		}

		// Token: 0x170006FF RID: 1791
		// (get) Token: 0x06002228 RID: 8744 RVA: 0x00334E24 File Offset: 0x00333024
		public virtual string PrefixDatabase
		{
			get
			{
				if (this.FieldAttr == null)
				{
					return "";
				}
				return this.FieldAttr.DatabaseString;
			}
		}

		// Token: 0x17000700 RID: 1792
		// (get) Token: 0x06002229 RID: 8745 RVA: 0x00334E3F File Offset: 0x0033303F
		public virtual string PrefixServer
		{
			get
			{
				if (this.FieldAttr == null)
				{
					return "";
				}
				return this.FieldAttr.ServerString;
			}
		}

		// Token: 0x0600222A RID: 8746 RVA: 0x00334E5A File Offset: 0x0033305A
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x0600222B RID: 8747 RVA: 0x00334E6A File Offset: 0x0033306A
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			this.Expr.acceptChildren(v);
			if (this.AliasClause != null)
			{
				this.AliasClause.acceptChildren(v);
			}
			v.postVisit(this);
		}

		// Token: 0x04001AD6 RID: 6870
		private TQualifyClause _qualifyClause;

		// Token: 0x04001AD7 RID: 6871
		private List<TExplicitDataTypeConversion> dataTypeConversionList;

		// Token: 0x04001AD8 RID: 6872
		private TObjectNameList targetColumns;

		// Token: 0x04001AD9 RID: 6873
		private TExpression expr;

		// Token: 0x04001ADA RID: 6874
		private bool placeHolder;
	}
}
